package com.project.controller;

import com.project.entity.Discuss;
import com.project.entity.KnowLedge;
import com.project.entity.Result;
import com.project.service.DiscussService;
import com.project.service.KnowLedgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/discuss")
public class DiscussController {
    @Autowired
    private DiscussService discussService;

    @GetMapping("/findById/{knowledgeId}")
    public Result findPage(@PathVariable Integer knowledgeId) {
        Result result = new Result();
        try {
            result.success("成功");
            List<KnowLedge> list = discussService.findById(knowledgeId);
            result.putData("list",list);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @PostMapping("insert")
    public Result findOneById(Discuss discuss){
        Result result = new Result();

        try {
            discussService.insert(discuss);
            result.success("插入成功");
        }catch (Exception e){

            e.printStackTrace();
            result.error("错误");
        }
        return result;
    }
}
